if (typeof SG == "undefined")
	var SG = new Object();
if (typeof SG.upload == "undefined")
	SG.upload = new Object();

SG.upload = function(id, url, flash, callback, error) {
	this.attributes = new Array();
	if (id) {
		this.setAttribute("id", id);
	} else {
		return;
	}
	if (url) {
		this.setAttribute("url", url);
	} else {
		return;
	}

	var _ext = (flash) ? new Array("FLV", "SWF") : new Array("BMP", "JPEG",
			"GIF", "PSD", "PNG", "TIFF", "TGA", "EPS", "JPG");
	this.setAttribute("ext", _ext);
	var _flash = (flash) ? flash : false;
	this.setAttribute("flash", _flash);
	if (callback) {
		this.setAttribute("callback", callback);
	}
	if (error) {
		this.setAttribute("error", error);
	}
}
SG.upload.prototype = {
	setAttribute : function(name, value) {
		this.attributes[name] = value;
	},
	getAttribute : function(name) {
		return this.attributes[name];
	},
	execute : function() {
		if (!this.checkExt()) {
			alert("不支持此格式！");
			return false;
		} else {
			this.ajax();
		}

		return false;
	},
	getDOM : function(id) {
		var dom = document.getElementById(id);
		return dom;
	},
	ajax : function() {
		$.ajaxFileUpload( {
			url : this.getAttribute("url"),
			secureuri : false,
			fileElementId : this.getAttribute("id"),
			dataType : 'json',
			success : function(data, status) {
				alert(data.tempUrl);
			},
			error : function(data, status, e) {
				alert("22");
			}
		});
	},
	bind : function() {
		var dom = this.getDOM(this.getAttribute("id"));
		if (dom.addEventListener) {
			dom.addEventListener("change", this.execute, false);
		} else if (dom.attachEvent) {
			dom.attachEvent("onchange", this.execute);
		}
		return;
	},
	writePic : function(path) {
		alert("not yet");
	},
	writeFlash : function(path) {
		alert('not yet');
	}

}
